package com.xiaomazi.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaomazi.common.utils.R;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaomazi.cms.entity.Banner;
import com.xiaomazi.cms.mapper.BannerMapper;
import com.xiaomazi.cms.service.BannerService;
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService{

    /**
     * 根据id降序查询两条Banner图
     * @return BannerList
     */
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @Override
    public R getAllBanner() {
        return R.ok().data("BannerList",this.query().orderByDesc("id").last("LIMIT 2").list());
    }

    /**
     * 分页查询后台Banner图列表
     * @param current 当前页
     * @param size    每页显示记录条数
     * @return BannerList
     */
    @Override
    public R getAllBannerList(Integer current, Integer size) {
        IPage<Banner> page = new Page<>(current,size);
        page = this.page(page);
        return R.ok().data("total",page.getTotal()).data("bannerList",page.getRecords());
    }
}
